home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / frasr182.zip / MISCRES.C < prev    next >
C/C++ Source or Header  |  1993-08-18  |  28KB  |  945 lines

  1. /*
  2.     Resident odds and ends that don't fit anywhere else.
  3. */
  4.  
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include <time.h>
  10. #ifndef XFRACT
  11. #include <stdarg.h>
  12. #include <io.h>
  13. #else
  14. #include <varargs.h>
  15. #endif
  16. #include <math.h>
  17. #ifdef __TURBOC__
  18. #include <dir.h>
  19. #endif
  20.  
  21. #include "fractint.h"
  22. #include "fractype.h"
  23. #include "helpdefs.h"
  24. #include "prototyp.h"
  25.  
  26. /* routines in this module    */
  27.  
  28. static    void trigdetails(char *);
  29. static void area();
  30.  
  31. int active_ovly = -1;
  32.  
  33. extern char IFSFileName[80];
  34. extern char IFSName[40];
  35. extern float far *ifs_defn;
  36. extern int  ifs_changed;
  37. extern int  ifs_type;
  38. extern int neworbittype;
  39. extern char temp[], temp1[256];   /* temporary strings          */
  40.  
  41. extern int  active_ovly;
  42. extern int  xdots, ydots;
  43. extern int  dotmode;
  44. extern int  show_orbit;
  45. extern int  debugflag;
  46. extern int  maxit;
  47. extern int  fractype;
  48. extern int  got_status,curpass,totpasses,currow,curcol;
  49. extern int  fileydots;
  50. extern int  xxstart,xxstop,yystart,yystop;
  51. extern int  display3d;
  52. extern char overwrite;
  53. extern int  inside;
  54. extern int  outside;
  55. extern double xxmax,xxmin,yymax,yymin,xx3rd,yy3rd;
  56.  
  57.  
  58. /* TW's static string consolidation campaign to help brain-dead compilers */
  59. char s_cantopen[]       = {"Can't open %s"};
  60. char s_cantwrite[]      = {"Can't write %s"};
  61. char s_cantcreate[]     = {"Can't create %s"};
  62. char s_cantunderstand[] = {"Can't understand %s"};
  63. char s_cantfind[]       = {"Can't find %s"};
  64.  
  65. /* call next when returning from resident routine and unsure whether
  66.    caller is an overlay which has been displaced */
  67. void restore_active_ovly()
  68. {
  69.  
  70.    switch (active_ovly) {
  71.       case OVLY_MISCOVL:  miscovl_overlay();  break;
  72.       case OVLY_CMDFILES: cmdfiles_overlay(); break;
  73.       case OVLY_HELP:      help_overlay();     break;
  74.       case OVLY_PROMPTS1: prompts1_overlay(); break;
  75.       case OVLY_PROMPTS2: prompts2_overlay(); break;
  76.       case OVLY_LOADFILE: loadfile_overlay(); break;
  77.       case OVLY_ROTATE:   rotate_overlay();   break;
  78.       case OVLY_PRINTER:  printer_overlay();  break;
  79.       case OVLY_LINE3D:   line3d_overlay();   break;
  80.       case OVLY_ENCODER:  encoder_overlay();  break;
  81.       case OVLY_CALCFRAC: calcfrac_overlay(); break;
  82.       case OVLY_INTRO:      intro_overlay();    break;
  83.       case OVLY_DECODER:  decoder_overlay();  break;
  84.       }
  85. }
  86.  
  87.  
  88. #ifndef XFRACT
  89. extern int splitpath(char *template,char *drive,char *dir,char *fname,char *ext);
  90. extern int makepath(char *template,char *drive,char *dir,char *fname,char *ext);
  91.  
  92. void findpath(char *filename, char *fullpathname) /* return full pathnames */
  93. {
  94.    char fname[FILE_MAX_FNAME];
  95.    char ext[FILE_MAX_EXT];
  96.    extern int first_init;
  97.    if (filename[0] == SLASHC || (filename[0] && filename[1] == ':')) {
  98.       if(access(filename,0)==0) {   /* file exists */
  99.          strcpy(fullpathname,filename);
  100.          return;
  101.          }
  102.       else {
  103.          splitpath(filename ,NULL,NULL,fname,ext);
  104.          makepath(filename,""   ,"" ,fname,ext);
  105.          }
  106.       }
  107.    fullpathname[0] = 0;             /* indicate none found */
  108. #ifdef __TURBOC__                /* look for the file */
  109.    strcpy(fullpathname,searchpath(filename));
  110. #else
  111.    _searchenv(filename,"PATH",fullpathname);
  112. #endif
  113.    if (fullpathname[0] != 0)            /* found it! */
  114.       if (strncmp(&fullpathname[2],SLASHSLASH,2) == 0) /* stupid klooge! */
  115.      strcpy(&fullpathname[3],filename);
  116. }
  117. #endif
  118.  
  119.  
  120. void notdiskmsg()
  121. {
  122. static char far sorrymsg[]={
  123. "This type may be slow using a real-disk based 'video' mode, but may not \n\
  124. be too bad if you have enough expanded or extended memory. Press <Esc> to \n\
  125. abort if it appears that your disk drive is working too hard."};
  126.    stopmsg(0,sorrymsg);
  127. }
  128.  
  129.  
  130. /* convert corners to center/mag */
  131. int cvtcentermag(double *Xctr, double *Yctr, double *Magnification)
  132. {
  133.    double Width, Height, Radius, Ratio;
  134.    Width  = xxmax - xxmin;
  135.    Height = yymax - yymin;
  136.    Ratio = Height / Width;
  137.    if(xx3rd != xxmin || yy3rd != yymin || Width < 0
  138.      || (Width > 1e-8 && (Ratio <= 0.74 || Ratio >= 0.76))
  139.      || Ratio < 0.66 || Ratio > 0.84)
  140.       return(0);
  141.    /* calculate center and magnification */
  142.    Radius = Height / 2.0;
  143.    *Xctr = xxmin + (Width / 2.0);
  144.    *Yctr = yymin + Radius;
  145.    *Magnification = 1.0 / Radius;
  146.    return(1);
  147. }
  148.  
  149.  
  150. void updatesavename(char *filename) /* go to the next file name */
  151. {
  152.    char *save, *hold;
  153.    char name[80],suffix[80];
  154.    char *dotptr;
  155.  
  156.    strcpy(name,filename);
  157.    suffix[0] = 0;
  158.    if ((dotptr = strrchr(name,'.')) != NULL
  159.      && dotptr > strrchr(name,SLASHC)) {
  160.       strcpy(suffix,dotptr);
  161.       *dotptr = 0;
  162.       }
  163.  
  164.    hold = name + strlen(name) - 1; /* start at the end */
  165.    while(hold >= name && (*hold == ' ' || isdigit(*hold))) /* skip backwards */
  166.       hold--;
  167.    hold++;            /* recover first digit */
  168.    while (*hold == '0')         /* skip leading zeros */
  169.       hold++;
  170.    save = hold;
  171.    while (*save) {        /* check for all nines */
  172.       if (*save != '9')
  173.      break;
  174.       save++;
  175.       }
  176.    if (!*save)            /* if the whole thing is nines then back */
  177.       save = hold - 1;        /* up one place. Note that this will eat */
  178.                 /* your last letter if you go to far.     */
  179.    else
  180.       save = hold;
  181.    sprintf(save,"%d",atoi(hold)+1); /* increment the number */
  182.    strcpy(filename,name);
  183.    strcat(filename,suffix);
  184. }
  185.  
  186. int check_writefile(char *name,char *ext)
  187. {
  188.  /* after v16 release, change encoder.c to also use this routine */
  189.    char openfile[80];
  190.    char opentype[20];
  191.    int i;
  192. nextname:
  193.    strcpy(openfile,name);
  194.    strcpy(opentype,ext);
  195.    for (i = 0; i < strlen(openfile); i++)
  196.       if (openfile[i] == '.') {
  197.      strcpy(opentype,&openfile[i]);
  198.      openfile[i] = 0;
  199.      }
  200.    strcat(openfile,opentype);
  201.    if (access(openfile,0) != 0) /* file doesn't exist */
  202.    {
  203.       strcpy(name,openfile);
  204.       return 0;
  205.     }
  206.    /* file already exists */
  207.    if (overwrite == 0) {
  208.       updatesavename(name);
  209.       goto nextname;
  210.       }
  211.    return 1;
  212. }
  213.  
  214. /* ('check_key()' was moved to FRACTINT.C for MSC7-overlay speed purposes) */
  215. /* ('timer()'     was moved to FRACTINT.C for MSC7-overlay speed purposes) */
  216.  
  217. BYTE trigndx[] = {SIN,SQR,SINH,COSH};
  218. #ifndef XFRACT
  219. void (*ltrig0)(void) = lStkSin;
  220. void (*ltrig1)(void) = lStkSqr;
  221. void (*ltrig2)(void) = lStkSinh;
  222. void (*ltrig3)(void) = lStkCosh;
  223. void (*mtrig0)(void) = mStkSin;
  224. void (*mtrig1)(void) = mStkSqr;
  225. void (*mtrig2)(void) = mStkSinh;
  226. void (*mtrig3)(void) = mStkCosh;
  227. #endif
  228. void (*dtrig0)(void) = dStkSin;
  229. void (*dtrig1)(void) = dStkSqr;
  230. void (*dtrig2)(void) = dStkSinh;
  231. void (*dtrig3)(void) = dStkCosh;
  232.  
  233. struct trig_funct_lst trigfn[] =
  234. /* changing the order of these alters meaning of *.fra file */
  235. /* maximum 6 characters in function names or recheck all related code */
  236. {
  237. #ifndef XFRACT
  238.    {"sin",   lStkSin,   dStkSin,   mStkSin   },
  239.    {"cosxx", lStkCosXX, dStkCosXX, mStkCosXX },
  240.    {"sinh",  lStkSinh,  dStkSinh,  mStkSinh  },
  241.    {"cosh",  lStkCosh,  dStkCosh,  mStkCosh  },
  242.    {"exp",   lStkExp,   dStkExp,   mStkExp   },
  243.    {"log",   lStkLog,   dStkLog,   mStkLog   },
  244.    {"sqr",   lStkSqr,   dStkSqr,   mStkSqr   },
  245.    {"recip", lStkRecip, dStkRecip, mStkRecip }, /* from recip on new in v16 */
  246.    {"ident", StkIdent,  StkIdent,  StkIdent  },
  247.    {"cos",   lStkCos,   dStkCos,   mStkCos   },
  248.    {"tan",   lStkTan,   dStkTan,   mStkTan   },
  249.    {"tanh",  lStkTanh,  dStkTanh,  mStkTanh  },
  250.    {"cotan", lStkCoTan, dStkCoTan, mStkCoTan },
  251.    {"cotanh",lStkCoTanh,dStkCoTanh,mStkCoTanh},
  252.    {"flip",  lStkFlip,  dStkFlip,  mStkFlip  },
  253.    {"conj",  lStkConj,  dStkConj,  mStkConj  },
  254.    {"zero",  lStkZero,  dStkZero,  mStkZero  },
  255. #else
  256.    {"sin",   dStkSin,   dStkSin,   dStkSin   },
  257.    {"cosxx", dStkCosXX, dStkCosXX, dStkCosXX },
  258.    {"sinh",  dStkSinh,  dStkSinh,  dStkSinh  },
  259.    {"cosh",  dStkCosh,  dStkCosh,  dStkCosh  },
  260.    {"exp",   dStkExp,   dStkExp,   dStkExp   },
  261.    {"log",   dStkLog,   dStkLog,   dStkLog   },
  262.    {"sqr",   dStkSqr,   dStkSqr,   dStkSqr   },
  263.    {"recip", dStkRecip, dStkRecip, dStkRecip }, /* fr